﻿
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using Utils;
using PanasonicWarranty.DAL;
namespace PanasonicWarranty.Business
{
    public partial class pa_MessagePattern
    {
    	#region public properties
		[Required(ErrorMessage="Message Code Required")]
		public string MessageCode { get; set; }
		public string Pattern { get; set; }
		public string Description { get; set; }
		#endregion

		#region constructor
		public pa_MessagePattern(){ }

		public pa_MessagePattern(IDataReader rd)
		{
			this.MessageCode = rd["MessageCode"].ToString();
			this.Pattern = rd["Pattern"].ToString();
			this.Description = rd["Description"].ToString();
		}
		#endregion

		#region private method
        private bool Create()
        {
            return DBpa_MessagePattern.Create(MessageCode, Pattern, Description);
        }

        private bool Update()
        {
            return DBpa_MessagePattern.Update(MessageCode, Pattern, Description);
        }
		#endregion

		#region public method
		public bool Save()
		{
            if(MessageCode != string.Empty)
            {
                return Update();
            }
            else
            {
                return Create();
            }
		}
		#endregion

		#region static method
        public static bool Delete(string MessageCode)
        {
            return DBpa_MessagePattern.Delete(MessageCode);
        }

        public static List<pa_MessagePattern> GetAll()
        {
            return ObjectClass.CreateList<pa_MessagePattern>(DBpa_MessagePattern.GetAll());
        }

        public static pa_MessagePattern GetByKey(string MessageCode)
        {
            return ObjectClass.CreateInstance<pa_MessagePattern>(DBpa_MessagePattern.GetByKey(MessageCode));
        }

        public static List<pa_MessagePattern> GetByTop(string top, string where, string order)
        {
            return ObjectClass.CreateList<pa_MessagePattern>(DBpa_MessagePattern.GetByTop(top, where, order));
        }
		#endregion
	}
}
